package com.mask.im.business.config;

import com.mask.im.business.interception.LimitInterception;
import com.mask.im.business.interception.PageInterception;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@SuppressWarnings("all")
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    private LimitInterception limitInterception;

    @Autowired
    private PageInterception pageInterception;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(limitInterception);
        registry.addInterceptor(pageInterception);
    }

    /**
     * 解决跨域
     *
     * @param registry
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {

        registry
                //运行所有方式请求
                .addMapping("/**")
                //运行跨域请求的域名
                .allowedOrigins("*")
                //是否允许证书
                .allowCredentials(true)
                //运行任何头
                .allowedHeaders("*")
                //运行的方法
                .allowedMethods("*");
    }
}
